package leetcode_800;

/**
 *@author 周杨
 *FindSmallestLetterGreaterThanTarget_744 返回一个字符数组里比target大的最近的数 是循环数组
 *describe:常规题 AC 36%
 *2018年10月16日 下午12:39:08
 */
public class FindSmallestLetterGreaterThanTarget_744 {
	public char nextGreatestLetter1(char[] letters, char target) {//二分查找
        int start = 0;
        int end = letters.length-1;
        while(start<end-1){
            int mid = (start+end)/2;
            if(target < letters[mid]) end = mid ;
            else if(target >= letters[mid]) start=mid ;
        }
        if (target >= letters[end]) return letters[0];
        else if(target >= letters[start]) return letters[end];
        else return letters[start];       
    }
	
	public char nextGreatestLetter(char[] letters, char target) {
        for(char c:letters) {
        	if(c>target)
        		return c;
        }
        return letters[0];
    }
}
